home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10561 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: newsfeeds.ans.net!interaccess!usenet
  2. From: brianmcg@interaccess.com (Brian V. McGroarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Getting date in UNIX
  5. Date: 18 Mar 1996 18:48:52 GMT
  6. Organization: Internet Squire
  7. Message-ID: <4ikb6k$g1e@nntp.interaccess.com>
  8. References: <4ik447$bn7@raffles.technet.sg>
  9. Reply-To: brianmcg@interaccess.com
  10. NNTP-Posting-Host: d51-isdn.nhe.interaccess.com
  11. X-Newsreader: Internet Squire 1.20
  12.  
  13. Leonard Sim wrote:
  14. >Can anyone please inform me how to obtain the date in UNIX C??
  15. >I just need the date in this format "dd/mm/yyyy". Thanks!!!
  16.  
  17. Look at "time()" and "ctime()" -- prototyped in time.h.
  18.  
  19. time_t time(time_t *timer) will fetch the time and day in seconds since
  20. midnight of Jan 1, 1970 and return them in a variable of type time_t
  21. (usually a 32-bit integer.)
  22.  
  23. With the number above, you can convert to the current date yourself, or you
  24. can look at char *ctime(time_t *time) (probably const time_t *time in
  25. libraries with stronger types).  "ctime()" will convert the seconds into a
  26. human-readable format, although it is not the format you specifically asked
  27. for.  I also don't know for sure that the format it converts to is standard
  28. across all systems... on mine I get "Mon Mar 18 12:48:53 1996" with a
  29. new-line and null terminator.
  30.  
  31. Be warned that the string ctime points to will be overwritten on subsequent
  32. local calls to the function -- be sure to copy the data into safe storage
  33. before running with it!
  34.  
  35. ---
  36. Brian Valters McGroarty -- brianmcg@bix.com
  37. phone/fax (847) 439-7714
  38.